﻿using System;
namespace Producers.Ehr.Xtee.Riik.Ee.Producer.Ehr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="katastriyksusega_seotud_objektid", Namespace="http://producers.ehr.xtee.riik.ee/producer/ehr", Target=typeof(KatastriyksusegaSeotudObjektid))]
    public class KatastriyksusegaSeotudObjektidSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IKatastriyksusegaSeotudObjektid clazz;
        
        public KatastriyksusegaSeotudObjektidSerializer(IKatastriyksusegaSeotudObjektid clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.TYHIVASTUS!=null) {
                Writer.WriteStartElement("TYHIVASTUS");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.TYHIVASTUS))).ToString());
                Writer.WriteEndElement();
            }
            for (int x = 0; ((clazz.KAYKEHIT != null) 
                        && (x < clazz.KAYKEHIT.Count)); x = (x + 1)) {
                if (clazz.KAYKEHIT[x]!=null) {
                    Writer.WriteStartElement("KAYK_EHIT");
                    global::Xtee.Core.SerializationMetadata metaKAYKEHIT = this.GetMetaData(clazz.KAYKEHIT[x]);
                    Writer.WriteTypeAttribute(metaKAYKEHIT.TypeQualifiedName.Namespace, metaKAYKEHIT.TypeQualifiedName.Name);
                    metaKAYKEHIT.NewSerializer(clazz.KAYKEHIT[x]).WriteXml(Writer);
                    Writer.WriteEndElement();
                }
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="TYHIVASTUS") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>katastriyksusega_seotud_objektid>TYHIVASTUS");
                }
                clazz.TYHIVASTUS = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("TYHIVASTUS")).Value;
            }
            if (Reader.LocalName=="KAYK_EHIT") {
                clazz.KAYKEHIT = new System.Collections.Generic.List<KatastriyksusegaSeotudObjektid.IKAYKEHITType>();
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "KAYK_EHIT")); ) {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>katastriyksusega_seotud_objektid>KAYK_EHIT");
                    }
                    global::Xtee.Core.SerializationMetadata metaKAYKEHIT = this.GetMetaData<KatastriyksusegaSeotudObjektid.IKAYKEHITType>(Reader, ">>katastriyksusega_seotud_objektid>KAYK_EHIT", "http://producers.ehr.xtee.riik.ee/producer/ehr");
                    KatastriyksusegaSeotudObjektid.IKAYKEHITType item = metaKAYKEHIT.NewEntity<KatastriyksusegaSeotudObjektid.IKAYKEHITType>();
                    clazz.KAYKEHIT.Add(item);
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("KAYK_EHIT");
                        metaKAYKEHIT.NewSerializer(item).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
            }
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>katastriyksusega_seotud_objektid>KAYK_EHIT", Namespace="http://producers.ehr.xtee.riik.ee/producer/ehr", Target=typeof(KatastriyksusegaSeotudObjektid.KAYKEHITType))]
        public class KAYKEHITTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected KatastriyksusegaSeotudObjektid.IKAYKEHITType clazz;
            
            public KAYKEHITTypeSerializer(KatastriyksusegaSeotudObjektid.IKAYKEHITType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                Writer.WriteStartElement("KYTUNNUS");
                if (clazz.KYTUNNUS!=null) {
                    Writer.WriteTypeAttribute("http://producers.ehr.xtee.riik.ee/producer/ehr", "KY_tunnusType");
                    Writer.WriteString(clazz.KYTUNNUS.ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : KYTUNNUS");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("EHR_KOOD");
                if (clazz.EHRKOOD!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.EHRKOOD))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : EHRKOOD");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("EHIT_ID");
                if (clazz.EHITID!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.EHITID))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : EHITID");
                }
                Writer.WriteEndElement();
                if (clazz.DATEUPDATED!=null) {
                    Writer.WriteStartElement("DATE_UPDATED");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.DATEUPDATED))).ToString());
                    Writer.WriteEndElement();
                }
                Writer.WriteStartElement("STAATUS_ID");
                if (clazz.STAATUSID!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.STAATUSID))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : STAATUSID");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("STAATUS_ID_TXT");
                if (clazz.STAATUSIDTXT!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.STAATUSIDTXT))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : STAATUSIDTXT");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("RAJATIS_HOONE");
                if (clazz.RAJATISHOONE!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.RAJATISHOONE))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : RAJATISHOONE");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("RAJATIS_HOONE_TXT");
                if (clazz.RAJATISHOONETXT!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.RAJATISHOONETXT))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : RAJATISHOONETXT");
                }
                Writer.WriteEndElement();
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="KYTUNNUS") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>katastriyksusega_seotud_objektid>KAYK_EHIT>KYTUNNUS");
                    }
                    clazz.KYTUNNUS = new global::Producers.Ehr.Xtee.Riik.Ee.Producer.Ehr.KYTunnusType(Reader.ReadElementString("KYTUNNUS"));
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>katastriyksusega_seotud_objektid>KAYK_EHIT>KYTUNNUS", Reader.LocalName);
                }
                if (Reader.LocalName=="EHR_KOOD") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>katastriyksusega_seotud_objektid>KAYK_EHIT>EHR_KOOD");
                    }
                    clazz.EHRKOOD = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("EHR_KOOD")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>katastriyksusega_seotud_objektid>KAYK_EHIT>EHR_KOOD", Reader.LocalName);
                }
                if (Reader.LocalName=="EHIT_ID") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>katastriyksusega_seotud_objektid>KAYK_EHIT>EHIT_ID");
                    }
                    clazz.EHITID = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("EHIT_ID")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>katastriyksusega_seotud_objektid>KAYK_EHIT>EHIT_ID", Reader.LocalName);
                }
                if (Reader.LocalName=="DATE_UPDATED") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>katastriyksusega_seotud_objektid>KAYK_EHIT>DATE_UPDATED");
                    }
                    clazz.DATEUPDATED = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("DATE_UPDATED")).Value;
                }
                if (Reader.LocalName=="STAATUS_ID") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>katastriyksusega_seotud_objektid>KAYK_EHIT>STAATUS_ID");
                    }
                    clazz.STAATUSID = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("STAATUS_ID")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>katastriyksusega_seotud_objektid>KAYK_EHIT>STAATUS_ID", Reader.LocalName);
                }
                if (Reader.LocalName=="STAATUS_ID_TXT") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>katastriyksusega_seotud_objektid>KAYK_EHIT>STAATUS_ID_TXT");
                    }
                    clazz.STAATUSIDTXT = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("STAATUS_ID_TXT")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>katastriyksusega_seotud_objektid>KAYK_EHIT>STAATUS_ID_TXT", Reader.LocalName);
                }
                if (Reader.LocalName=="RAJATIS_HOONE") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>katastriyksusega_seotud_objektid>KAYK_EHIT>RAJATIS_HOONE");
                    }
                    clazz.RAJATISHOONE = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("RAJATIS_HOONE")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>katastriyksusega_seotud_objektid>KAYK_EHIT>RAJATIS_HOONE", Reader.LocalName);
                }
                if (Reader.LocalName=="RAJATIS_HOONE_TXT") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>katastriyksusega_seotud_objektid>KAYK_EHIT>RAJATIS_HOONE_TXT");
                    }
                    clazz.RAJATISHOONETXT = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("RAJATIS_HOONE_TXT")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>katastriyksusega_seotud_objektid>KAYK_EHIT>RAJATIS_HOONE_TXT", Reader.LocalName);
                }
            }
        }
    }
}
